<?
	   layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
<link type="text/css" rel="stylesheet" href="static/vendors/jquery-bootstrap-wizard/custom.css">
<link type="text/css" rel="stylesheet" href="static/vendors/jquery-steps/css/jquery.steps.css">

<div class="col-lg-12">
    <div class="portlet box portlet-green">
        <div class="portlet-body">
            <div id="rootwizard-custom-circle">
                <div class="navbar" style="margin-top: -50px;margin-bottom: -10px;">
                    <div class="navbar-inner">
                        <ul>
                            <li><a href="#tab1-wizard-custom-circle" data-toggle="tab"><i class="glyphicon glyphicon-edit"></i><p class="anchor">数据源</p></a>
                            </li>
                            <li><a href="#tab2-wizard-custom-circle" data-toggle="tab"><i class="glyphicon glyphicon-edit"></i><p class="anchor">参数</p></a>
                            </li>
                            <li><a href="#tab3-wizard-custom-circle" data-toggle="tab"><i class="glyphicon glyphicon-check"></i><p class="anchor">对应字段</p></a>
                            </li>
                        </ul>
                    </div>
                </div>
<!--导航条
               <div id="bar" class="progress active">
                    <div class="bar progress-bar progress-bar-primary"></div>
                 </div>
-->
                <div class="tab-content">
                    <div id="tab1-wizard-custom-circle" class="tab-pane" style="height: 550px">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="inputStreet" class="control-label">数据导入名称 <span class='require'>*</span>
                                    </label>
                                    <input id="name" type="text" placeholder="" class="form-control" /><i class="alert alert-hide">请输入数据导入名称！</i>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="inputStreet" class="control-label">数据导入描述 <span class='require'>*</span>
                                    </label>
                                    <input id="description" type="text" placeholder="" class="form-control" /><i class="alert alert-hide">请输入数据导入描述！</i>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                   <label for="inputStreet" class="control-label">数据源名称 <span class='require'>*</span></label>
                                   <div>
                                    	<input id="dataSourceName" type="text" placeholder="" class="form-control" disabled="true"  style="width:740px;height:30px;float:left"/>
                                   		<button  onclick="shuju()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle" style="width:80px;height:30px;">选择...</button>
										<input id="dataSourceId" type="hidden" value="" class="form-control" />
										<input id="dataSourceType" type="hidden" value="" class="form-control" />
									</div>                             
                                    <i class="alert alert-hide">请选择一个数据源 ！</i>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                   <label for="inputStreet" class="control-label">知识库名称 <span class='require'>*</span></label>
                                   <div>
                                    	<input id="parentclassname" type="text" placeholder=""  class="form-control" disabled="true"  style="width:740px;height:30px;float:left"/>
									    <button  onclick="saveclassZTree()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle" style="width:80px;height:30px;">选择...</button>	
									    <input id="parentClassid" type="hidden" value="" class="form-control" />
									</div>                                 
                                    <i class="alert alert-hide">请选择一个知识库 ！</i>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="tab2-wizard-custom-circle" class="tab-pane" style="height: 550px">
	                        <div class="row" id="txt">
	                            <div class="col-md-12">
	                                <div class="form-group">
							             <label for="inputStreet" class="control-label">上传txt文件 <span class='require'>*</span>
	                                    </label>
							                <input id="uploadFile" type="file"  placeholder="" class="form-control" accept=".txt" onclick="clearsjy();"><i class="alert alert-hide">请上传txt文件！</i>
							                <div class="form-group">
								                 <input id="btnUpload" type="submit" name="submit" class="btn btn-success" value="上传"/>
								                  <input id="filePath" type="hidden" value="" class="form-control" />
								                <div role="progressbar" id="progressbar" aria-valuetransitiongoal="1" class="progress-bar progress-bar-success" aria-valuenow="1" style="width: 0%;"></div>
							                </div>
	                                </div>
	                            </div>
	                            <div class="col-md-12">
	                                <div class="form-group">
	                                    <label for="inputStreet" class="control-label">格式类型 <span class='require'>*</span>
	                                    </label>
	                                    <select id="txt_type" class="form-control" onclick="clearsjy();txtSpitShow();">
	                                        <option value="0">一行一条数据库数据</option>
	                                        <option value="1">多行一条数据库数据</option>
                                   	 	</select>
	                                </div>
	                            </div>
	                            <div class="col-md-6">
	                                <div class="form-group">
	                                    <label for="inputStreet" class="control-label">记录分隔符 <span class='require'>*</span>
	                                    </label>
	                                   <input id="field_field_split" type="text" placeholder="" class="form-control" onchange="clearsjy();"/><i class="alert alert-hide">请输入记录分隔符！</i>
	                                </div>
	                            </div>
	                             <div class="col-md-6">
	                                <div class="form-group">
	                                    <label for="inputStreet" class="control-label">字段分隔符 <span class='require'>*</span>
	                                    </label>
	                                   <input id="field_split" type="text" placeholder="" class="form-control" onchange="clearsjy();"/><i class="alert alert-hide">请输入字段分隔符！</i>
	                                </div>
	                              </div>
	                        </div>
	                        <div class="row" id="xml">
	                            <div class="col-md-12">
	                                <div class="form-group">
	                                    <label for="inputStreet" class="control-label">上传xml文件 <span class='require'>*</span>
	                                    </label>
<!-- 	                                    <input id="uploadFile" type="file"  placeholder="" class="form-control" accept=".xml"><i class="alert alert-hide">请上传xml文件！</i> -->
							                <input id="uploadFile" type="file"  placeholder="" class="form-control" accept=".xml" onclick="clearsjy();"><i class="alert alert-hide">请上传xml文件！</i>
							                <div class="form-group">
								                 <input id="btnUpload" type="submit" name="submit" class="btn btn-success" value="上传"/>
								                  <input id="filePath" type="hidden" value="" class="form-control" />
								                <div role="progressbar" id="progressbar" aria-valuetransitiongoal="1" class="progress-bar progress-bar-success" aria-valuenow="1" style="width: 0%;"></div>
							                </div>
	                                </div>
	                            </div>
	                            <div class="col-md-12">
	                                <div class="form-group">
	                                    <label for="inputStreet" class="control-label">元素节点xpath路径 <span class='require'>*</span>
	                                    </label>
	                                    <input id="elementPath" type="text" placeholder="" class="form-control"/><i class="alert alert-hide">请输入xpath路径！</i>
	                                </div>
	                            </div>
                    		</div>
	                        <div class="row" id="excel">
	                            <div class="col-md-12">
	                                <div class="form-group">
<!-- 	                                    <label for="inputStreet" class="control-label">上传文件 <span class='require'>*</span> -->
<!-- 	                                    </label> -->
<!-- 	                                    <input id="uploadFile" type="file"  placeholder="" class="form-control" onchange="clearsjy();getSheetName();" accept=".xls,.xlsx"> -->
<!-- 	                                	<i class="alert alert-hide">请上传Excel文件！</i> -->
	                                	  <label for="inputStreet" class="control-label">上传excel文件 <span class='require'>*</span>
	                                    </label>
							                <input id="uploadFile" type="file"  placeholder="" class="form-control" accept=".xls,.xlsx" onclick="clearsjy();"><i class="alert alert-hide">请上传excel文件！</i>
							                <div class="form-group">
								                 <input id="btnUpload" type="submit" name="submit" class="btn btn-success" value="上传"/>
								                  <input id="filePath" type="hidden" value="" class="form-control" />
								                <div role="progressbar" id="progressbar" aria-valuetransitiongoal="1" class="progress-bar progress-bar-success" aria-valuenow="1" style="width: 0%;"></div>
							                </div>
	                                </div>
	                            </div>
	                            <div class="col-md-12">
	                                <div class="form-group">
	                                    <label for="inputStreet" class="control-label">sheet名称 <span class='require'>*</span>
	                                    </label>
	                                    <select id="sheetName" class="form-control" onclick="getFileFied();">
                                   		</select>
	                                </div>
	                            </div>
                    		</div>
	                        <div class="row" id="json">
	                            <div class="col-md-12">
	                                <div class="form-group">
<!-- 	                                    <label for="inputStreet" class="control-label">上传文件 <span class='require'>*</span> -->
<!-- 	                                    </label> -->
<!-- 	                                    <input id="uploadFile" type="file"  placeholder="" class="form-control" onchange="getFileFied()" accept=".json,.txt"><i class="alert alert-hide">请上传json文件！</i> -->
	                                	  <label for="inputStreet" class="control-label">上传json文件 <span class='require'>*</span>
	                                    </label>
							                <input id="uploadFile" type="file"  placeholder="" class="form-control" accept=".json,.txt" onclick="clearsjy();"><i class="alert alert-hide">请上传json文件！</i>
							                <div class="form-group">
								                 <input id="btnUpload" type="submit" name="submit" class="btn btn-success" value="上传"/>
								                  <input id="filePath" type="hidden" value="" class="form-control" />
								                <div role="progressbar" id="progressbar" aria-valuetransitiongoal="1" class="progress-bar progress-bar-success" aria-valuenow="1" style="width: 0%;"></div>
							                </div>
	                                </div>
	                            </div>
                    		</div>
	                        <div class="row" id="mysql">
	                            <div class="col-md-12">
	                                <div class="form-group">
	                                    <label for="inputStreet" class="control-label">数据源数据库名称 <span class='require'>*</span>
	                                    </label>
	                                     <select id="mysql-database" class="form-control" onchange="getTableName(this);">
                                   		</select>
	                                </div>
	                            </div>
                    		</div>
	                        <div class="row" id="sqlserver">
	                            <div class="col-md-12">
	                                <div class="form-group">
	                                      <label for="inputStreet" style="font-size: large;" class="control-label">此页无需配置</span>
	                                    </label>
	                                </div>
	                            </div>
                    		</div>
	                        <div class="row" id="oracle">
	                            <div class="col-md-12">
	                                <div class="form-group">
	                                      <label for="inputStreet" style="font-size: large;" class="control-label">此页无需配置</span>
	                                    </label>
	                                    
	                                </div>
	                            </div>
                    		</div>
	                        <div class="row" id="access">
	                            <div class="col-md-12">
	                                <div class="form-group">
	                                      <label for="inputStreet" style="font-size: large;" class="control-label">此页无需配置</span>
	                                    </label>
	                                </div>
	                            </div>
                    		</div>
	                        <div class="row" id="mongodb">
	                            <div class="col-md-12">
	                                <div class="form-group">
	                                     <label for="inputStreet" class="control-label">mongodb集合名称 <span class='require'>*</span>
	                                    </label>
	                                       <select id="mongodb-collection" class="form-control">
                                   		</select>
                                   		<i class="alert alert-hide">请选择数据源集合名称！</i>
	                                </div>
	                            </div>
                    		</div>
                    </div>
                    <div id="tab3-wizard-custom-circle" class="tab-pane fadeIn" style="height: 550px">
                        <div class="row" id="txt_json_xml_excel">
                        	 <div class="col-md-6">
	                                <div class="form-group">
									     <label for="inputStreet" class="control-label">知识库字段名称 <span class='require'>*</span>
	                                    </label>
									    <div class="zsk" >
									    </div>
	                                </div>
	                               </div>
                        		 <div class="col-md-6">
	                                <div class="form-group">
	                                     <label for="inputStreet" class="control-label">数据源字段名称 <span class='require'>*</span>
	                                    </label>
	                                    <div class="sjy">
									    </div>
	                                </div>
	                            </div>
	                            <div class="col-md-12">
	                             	<div class="form-group">
	                               		<button type="button" class="btn btn-success" style="margin-right: 20px;" onclick="addCorresponding();">添加</button>
	                               		<button type="button" class="btn btn-success" style="margin-right: 20px;" onclick="refreshAndempty('0');">刷新字段并清空对应关系</button>
	                               	</div>
	                             </div>
	                             <div class="col-md-12">
									<div id="corresponding_field" class="panel-body" style="height: 200px;overflow: auto;background-color: rgba(238, 238, 238, 0.52);">
										<span class='demo-btn' id='spanShow'>
											
										</span>
									</div>
								</div>
                        </div>
                        <div class="row" id="mysql_oracle_access_sqlserver_mongodb">
                        	 <div class="col-md-12">
	                                <div class="form-group">
	                                	 <label for="inputStreet" class="control-label">数据库表 <span class='require'>*</span>
	                                    	</label>
									    <select id="sql_tableName" class="form-control" onclick="getField(this);">
                                   		</select>
	                                </div>
	                          </div>
                        	 <div class="col-md-6">
	                                <div class="form-group">
	                                	 <label for="inputStreet" class="control-label">知识库字段名称 <span class='require'>*</span>
	                                    </label>
									    <div class="zsk" >
									    </div>
	                                </div>
	                               </div>
                        		 <div class="col-md-6">
	                                <div class="form-group">
	                                	 <label for="inputStreet" class="control-label">数据源字段名称 <span class='require'>*</span>
	                                    </label>
	                                    <div class="sjy" >
									    </div>
	                                </div>
	                            </div>
	                            <div class="col-md-12">
	                             	<div class="form-group">
	                               		<button type="button" class="btn btn-success" style="margin-right: 20px;" onclick="addCorresponding();">添加</button>
	                               		<button type="button" class="btn btn-success" style="margin-right: 20px;" onclick="refreshAndempty('1');">刷新字段并清空对应关系</button>
	                               	</div>
	                             </div>
	                             <div class="col-md-12">
									<div id="corresponding_field" class="panel-body" style="height: 200px;overflow: auto;background-color: rgba(238, 238, 238, 0.52);">
										<span class='demo-btn' id='spanShow'>
											
										</span>
									</div>
								</div>
                        </div>
                   </div>
                    <div class="action text-right" style="margin-top: 10px;">
                        <button type="button" name="previous" value="Previous" id="up" class="btn btn-info button-previous">
                        <i class="fa fa-arrow-circle-o-left mrx"></i>上一步</button>
                        <button type="button" name="next" value="Next" id="down" class="btn btn-info button-next mlm">
                        	下一步<i class="fa fa-arrow-circle-o-right mlx"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?}?>
   <script src="static/vendors/jquery-validate/jquery.validate.min.js"></script>
   <script src="static/vendors/jquery-steps/js/jquery.steps.min.js"></script>
   <script src="static/vendors/jquery-bootstrap-wizard/jquery.bootstrap.wizard.min.js"></script>
   <script src="static/js/form-wizard.js"></script>
   <script src="static/vendors/iCheck/icheck.min.js"></script>
   <script src="static/vendors/iCheck/custom.min.js"></script>
   <script src="static/js/ui-checkbox-radio.js"></script>
<script type="text/javascript">

//添加对应关系
var corresponding_index=0;
function addCorresponding(){
	var zsk=$(".zsk .radio .checked").parents('.radio').attr("value");
	var zsk_div=$(".zsk .radio .checked").parents('.radio');
	var sjy=$(".sjy .radio .checked").parents('.radio').attr("value");
	if(zsk=="" || zsk==undefined){
		layer.msg("请选择知识库字段名称!", {icon: 5});
		return;
	}
	if(sjy=="" || sjy==undefined){
		layer.msg("请选择数据源字段名称!", {icon: 5});
		return;
	}
	var html='';
	html+='<div id="corresponding_'+corresponding_index+'">';
	html+='<button id="be_id" name="buValueColor" type="button" class="btn btn-green btn-square"  style="margin-top:0px;margin-bottom: 10px;">';
	html+=zsk;
	html+='</button> <span style="font-size: 20px;">➤</span>';
	html+='<button id="af_id" name="buValueColor" type="button" class="btn btn-green btn-square" style="margin-top:0px;margin-bottom: 10px; margin-right: 0px;">';
	html+=sjy;
	html+='</button>';
	html+='<a href="javascript:delCorresponding(';
	html+=corresponding_index+')" style="font-size: 18px; margin-right: 5px;"><i style="margin-left: -3px;" class="fa fa-times-circle-o"></i></a></div>';
	$("#corresponding_field #spanShow").append(html); 
	corresponding_index=corresponding_index+1;
	zsk_div.remove()
	
}
//删除对应关系
function delCorresponding(index){
	var be=$("#corresponding_field #spanShow #corresponding_"+index+" #be_id").text();
	$("#corresponding_field #spanShow #corresponding_"+index).remove();
	$(".zsk").append('<div class="radio" name="zsk" value="'+be+'"><ins></ins><span>'+be+'</span></div>');
}
//保存
function save(){
	var a="0";
	$("input").each(function(){
		if (!$(this).val()) {
            $(this).css('border-color', 'red');
            $(this).parent().parent().find("i.alert").removeClass("alert-hide");
            a="1";
        } else {
            $(this).parent().parent().find("i.alert").addClass("alert-hide");
        }
    });
		if(a=="1"){
			layer.msg("请继续完善信息!", {icon: 5});
		}else{
			var corresponding=getCorrespondingField();
			if(corresponding=="}"){
				layer.msg("请添加知识库与数据源之间的字段关系!", {icon: 5});
				return;
			}
			var id=$("#id").val();
			var name=$("#name").val();
			var description=$("#description").val();
			var classid=$("#parentClassid").val();
			var dataSourceId=$("#dataSourceId").val();
			var dataSourceType=$("#dataSourceType").val();//数据源类型
			//????
			var filePath=$("#filePath").val();
			var txt_type=$("#txt_type option:selected").val();
			var field_field_split=$("#field_field_split").val();
			var field_split=$("#field_split").val();
			var elementPath=$("#elementPath").val();
			var sheetName=$("#sheetName").val();
			var mysql_database=$("#mysql-database option:selected").val();
			var mongodb_collection=$("#mongodb-collection option:selected").val();
			var sql_tableName=$("#sql_tableName option:selected").val();
			var corresponding=getCorrespondingField();
			$.ajax({
				type : "post",
				url : "./dataHandlingSave.do",
				data : {
					"id":id,
					"name":name,
					"description":description,
					"classid":classid,
					"dataSourceId":dataSourceId,
					"dataSourceType":dataSourceType,
					"filePath":filePath==undefined?null:filePath,
					"txt_type":txt_type==undefined?null:txt_type,
					"field_field_split":field_field_split==undefined?null:field_field_split,
					"field_split":field_split==undefined?null:field_split,
					"elementPath":elementPath==undefined?null:elementPath,
					"sheetName":sheetName==undefined?null:sheetName,
					"mysql_database":mysql_database==undefined?null:mysql_database,
					"mongodb_collection":mongodb_collection==undefined?null:mongodb_collection,
					"sql_tableName":sql_tableName==undefined?null:sql_tableName,
					"corresponding":corresponding,
					"type":"0"
				},
				dataType : "json",
				success : function(data) {
					 var index = parent.layer.getFrameIndex(window.name); 
			         window.parent.get();
			         parent.layer.msg("添加成功", {icon: 6});
			         parent.layer.close(index); 
				},
				error : function(data) {
					layer.msg("请求失败！", {icon: 2});
				}
			});
		}
}
//获取对应字段
function getCorrespondingField(){
	var corresponding="{";
	$("button[id='be_id']").each(function(){
		corresponding+="\""+ $(this).text()+"\"";
		corresponding+=":";
		corresponding+="\""+ $(this).next().next().text()+"\"";
		corresponding+=",";
	});
	corresponding = corresponding.substring(0,corresponding.length-1) + "}" ;
	return corresponding;
}

//数据源
function shuju() {
	parent.layer.open({
		type : 2,
		area : [ '700px', '530px' ],
		fix : false, //不固定
		scrollbar : false,
		shadeClose : true,
		//move : false,
		title:"选择数据源",
		skin : 'layui-layer-rim', //加上边框
		btn : [ '保存 ', '关闭' ],
		content : ["data-handling-import-source-from.html?winName="+window.name, 'no'],
		yes : function(index,layer) {	
		  var iframeWin = parent.window[layer.find('iframe')[0]['name']];
		  iframeWin.save();
		},
		cancel : function(index) {
		},
		end: function () {
			var sourceType=$("#dataSourceType").val();
			var dataSourceId=$("#dataSourceId").val();
			removeElement(sourceType);
			getDataBaseOrTableName(sourceType,dataSourceId);
		}
	});
};
//点击数据源应该获取的部分---获取数据库或者数据库表
function getDataBaseOrTableName(sourceType,dataSourceId){
	if(sourceType == "mysql"){//获取数据库库
		$("#mysql-database option").remove();
		$.ajax({
			type : "post",
			url : "./dataHandlingImportDataBase.do",
			data : {
				"dataSourceId":dataSourceId
			},
			dataType : "json",
			success : function(data) {
				var jsonO = eval(data);
				if(jsonO[0].info =="0"){
					layer.msg("没有获取到数据库名称!", {icon: 5});
				}else{
					var dataRole = eval(jsonO[0].info);
					for(var i= 0; i< dataRole.length;i++){
						$("#mysql-database").append('<option value="'+dataRole[i].Database+'">'+dataRole[i].Database+'</option>');
					}
				}
				getTableName("init_table");//这里表示初始化
			},
			error : function(data) {
				layer.msg("请求失败！", {icon: 2});
			}
		});
	}
	if(sourceType == "oracle" || sourceType == "access" || sourceType == "sqlserver" ){//直接获取表
		getTableName('');
	}
	if(sourceType == "mongodb"){//获取集合
		
	}
}
//获取表名
function getTableName(databaseName){
	var dataSourceId=$("#dataSourceId").val();
	$("#sql_tableName option").remove();
	$.ajax({
		type : "post",
		url : "./DataHandlingTableName.do",
		data : {
			"dataSourceId":dataSourceId,
			"dataBaseName":databaseName==''?'':$("#mysql-database option:selected").val()
		},
		dataType : "json",
		success : function(data) {
			var jsonO = eval(data);
			if(jsonO[0].info =="0"){
				layer.msg("没有获取到表名称!", {icon: 5});
			}else{
				var dataRole = eval(jsonO[0].info);
				for(var i= 0; i< dataRole.length;i++){
					$("#sql_tableName").append('<option value="'+dataRole[i].NAME+'">'+dataRole[i].NAME+'</option>');
				}
				getField("init_field")
			}
			
		},
		error : function(data) {
			layer.msg("请求失败！", {icon: 2});
		}
	});
}
//获取字段
function getField(tableName){
	var dataSourceId=$("#dataSourceId").val();
	var dataBaseName=$("#mysql-database option:selected").val();
	$(".sjy .radio").remove();
	$.ajax({
		type : "post",
		url : "./DataHandlingFieldName.do",
		data : {
			"dataSourceId":dataSourceId,
			"tableName":$("#sql_tableName option:selected").val(),
			"dataBaseName":dataBaseName
		},
		dataType : "json",
		success : function(data) {
			var jsonO = eval(data);
			if(jsonO[0].info =="0"){
				layer.msg("没有获取到字段信息!", {icon: 5});
			}else{
				var dataRole = eval(jsonO[0].info);
				for(var i= 0; i< dataRole.length;i++){
					$(".sjy").append('<div class="radio" name="sjy" value="'+dataRole[i].columnName+'"><ins></ins><span>'+dataRole[i].columnName+'</span></div>');
				}
			}
		},
		error : function(data) {
			layer.msg("请求失败！", {icon: 2});
		}
	});
}
//知识库
function saveclassZTree() {
	$(".zsk .radio").remove();
	parent.layer.open({
		type : 2,
		area : [ '500px', '400px' ],
		fix : false, //不固定
		scrollbar : false,
		shadeClose : true,
		///move : false,
		title:"导入数据的类",
		skin : 'layui-layer-rim', //加上边框
		btn : [ '保存 ', '关闭' ],
		content : ["knowledge-Classes-class-zTree.html?winName="+window.name, 'no'],
		yes : function(index,layer) {		
		  var iframeWin = parent.window[layer.find('iframe')[0]['name']];
		  			  iframeWin.save();
		},
		cancel : function(index) {
		},
		end: function () {
			$(".zsk .radio").remove();
			knowledgeDataProperty();
			knowledgeObjectProperty();
		}
	});
};
//知识库数据属性
function knowledgeDataProperty(){
	$("#corresponding_field span div").remove();
	var classid=$("#parentClassid").val();
	$.ajax({
		type : "post",
		url : "./KnowledgeDataPropertyList.do",
		data : {
			"lid" : classid
		},
		dataType : "json",
		async : false,
		success : function(data) {
			$(".zsk").append('<div class="radio" name="zsk" value="id"><ins></ins><span>id</span></div>');
			for ( var i = 0; i < data.length; i++) {
				$(".zsk").append('<div class="radio" name="zsk" value="'+data[i].nameen+'"><ins></ins><span>'+data[i].nameen+'</span></div>');
			}
		},
		error : function(data) {
			layer.msg("请求失败！", {icon: 2});
		}
	});

};
//知识库对象属性
function knowledgeObjectProperty(){
	$("#corresponding_field span div").remove();
	var classid=$("#parentClassid").val();
	$.ajax({
		type : "post",
		url : "./KnowledgeObjectPropertyList.do",
		data : {
			"lid" : classid
		},
		dataType : "json",
		async : false,
		success : function(data) {
			for ( var i = 0; i < data.length; i++) {
				$(".zsk").append('<div class="radio" name="zsk" value="'+data[i].nameen+'"><ins></ins><span>'+data[i].nameen+'</span></div>');
			}
		},
		error : function(data) {
			layer.msg("请求失败！", {icon: 2});
		}
	});
}

var htmltxt = $("div #txt").prop("outerHTML");
var htmljson = $("div #json").prop("outerHTML");
var htmlexcel = $("div #excel").prop("outerHTML");
var htmlxml = $("div #xml").prop("outerHTML");
var htmlmysql = $("div #mysql").prop("outerHTML");
var htmloracle = $("div #oracle").prop("outerHTML");
var htmlaccess = $("div #access").prop("outerHTML");
var htmlsqlserver = $("div #sqlserver").prop("outerHTML");
var htmlmongodb = $("div #mongodb").prop("outerHTML");
var html_txt = $("div #txt_json_xml_excel").prop("outerHTML");
var html_sql = $("div #mysql_oracle_access_sqlserver_mongodb").prop("outerHTML");
//切换 不同类型，显示不同页面
function removeElement(type){
 	$("div #txt").remove();
	$("div #xml").remove();
	$("div #excel").remove();
	$("div #json").remove();
	$("div #mysql").remove();
	$("div #oracle").remove();
	$("div #access").remove();
	$("div #sqlserver").remove();
	$("div #mongodb").remove();
	$("div #txt_json_xml_excel").remove();
	$("div #mysql_oracle_access_sqlserver_mongodb").remove();
	if(type=="txt"){
		$("#tab2-wizard-custom-circle").append(htmltxt);
		$("#tab3-wizard-custom-circle").append(html_txt);
	}
	if(type=="xml"){
		$("#tab2-wizard-custom-circle").append(htmlxml);
		$("#tab3-wizard-custom-circle").append(html_txt);
	}
	if(type=="excel"){
		$("#tab2-wizard-custom-circle").append(htmlexcel);
		$("#tab3-wizard-custom-circle").append(html_txt);
	}
	if(type=="json"){
		$("#tab2-wizard-custom-circle").append(htmljson);
		$("#tab3-wizard-custom-circle").append(html_txt);
	}
	if(type=="mysql"){
		$("#tab2-wizard-custom-circle").append(htmlmysql);
		$("#tab3-wizard-custom-circle").append(html_sql);
	}
	if(type=="oracle"){
		$("#tab2-wizard-custom-circle").append(htmloracle);
		$("#tab3-wizard-custom-circle").append(html_sql);
	}
	if(type=="access"){
		$("#tab2-wizard-custom-circle").append(htmlaccess);
		$("#tab3-wizard-custom-circle").append(html_sql);
	}
	if(type=="sqlserver"){
		$("#tab2-wizard-custom-circle").append(htmlsqlserver);
		$("#tab3-wizard-custom-circle").append(html_sql);
	}
	if(type=="mongodb"){
		$("#tab2-wizard-custom-circle").append(htmlmongodb);
		$("#tab3-wizard-custom-circle").append(html_sql);
	}
	upload();
}

//txt分割符框的显示部分
function txtSpitShow(){
	var txt_type = $("#txt_type option:selected").val();
	if(txt_type == "0"){
		$("#field_field_split").val("");
		$("#field_field_split").removeAttr("disabled");

	}else{
		$("#field_field_split").attr("disabled","true"); 
		$("#field_field_split").val("Needn't input!");
	}
}
//Excel 获取sheet名称
function getSheetName(){
	$("#sheetName option").remove();
	var sourceType=$("#dataSourceType").val();
	//????
	var inPath=$("#filePath").val();
	$.ajax({
		type : "post",
		url : "./DataHandlingImportSheetName.do",
		data : {
			"inPath":inPath
		},
		dataType : "json",
		async : false,
		success : function(data) {
			var jsonO = eval(data);
			if(jsonO[0].info =="0"){
				layer.msg("没有获取到Sheet名称!", {icon: 5});
			}else{
				var dataRole = eval(jsonO[0].info);
				for(var i= 0; i< dataRole.length;i++){
					$("#sheetName").append('<option value="'+dataRole[i].sheetName+'">'+dataRole[i].sheetName+'</option>');
				}
				if(dataRole.length>0){
					getFileFied();
				}
			}
		},
		error : function(data) {
			layer.msg("请求失败！", {icon: 2});
		}
	});
}


//上传文件后获取数据源字段
function getFileFied(){
	$("#corresponding_field span div").remove();
	$(".sjy .radio").remove();
	var sourceType=$("#dataSourceType").val();
	//????
	var inPath=$("#filePath").val();
	var txt_type=$("#txt_type option:selected").val();
	var field_field_split=$("#field_field_split").val();
	var field_split=$("#field_split").val();
	var elementPath=$("#elementPath").val();
	var sheetName=$("#sheetName option:selected").val();

	$.ajax({
		type : "post",
		url : "./DataHandlingFileFieldName.do",
		data : {
			"inPath" : inPath,
			"sourceType":sourceType,
			"txt_type":txt_type,
			"field_field_split":field_field_split,
			"field_split":field_split,
			"elementPath":elementPath,
			"sheetName":sheetName
		},
		dataType : "json",
		async : false,
		success : function(data) {
			var jsonO = eval(data);
			if(jsonO[0].info =="0"){
				layer.msg("没有获取到字段信息!", {icon: 5});
			}else{
				var dataRole = eval(jsonO[0].info);
				for(var i= 0; i< dataRole.length;i++){
					$(".sjy").append('<div class="radio" name="sjy" value="'+dataRole[i].fieldName+'"><ins></ins><span>'+dataRole[i].fieldName+'</span></div>');
				}
			}
		},
		error : function(data) {
			layer.msg("请求失败！", {icon: 2});
		}
	});
}

//刷新并清空知识库字段和数据源字段
function refreshAndempty(type){
	if(type=='0'){
		getFileFied();
	}
	$(".zsk .radio").remove();
	knowledgeDataProperty();
	knowledgeObjectProperty();
}
//清空数据源字段
function clearsjy(){
	$(".sjy .radio").remove();
}
//上一页下一页
/************ #rootwizard-custom-circle ***********/
$('#rootwizard-custom-circle').bootstrapWizard({
    onTabShow: function(tab, navigation, index) {
        var $total = navigation.find('li').length;
        var $current = index+1;
       
        var $percent = ($current/$total) * 100;
        $('#rootwizard-custom-circle').find('.bar').css({width:$percent+'%'});
    },
    'onNext': function(tab, navigation, index) {
        // select id of current tab content
        var $id = tab.find("a").attr("href");
        var $approved = 1;
        // Check all input validation
        $($id + " input").each(function(){
            if (!$(this).val()) {
                $(this).css('border-color', 'red');
                $(this).parent().parent().find("i.alert").removeClass("alert-hide");
                $approved = 0;
            } else {
                $(this).parent().parent().find("i.alert").addClass("alert-hide");
            }
        });
        if ($approved !== 1) return false;
    },
    'onTabClick': function(tab, navigation, index) {
        // select id of current tab content
        var $id = tab.find("a").attr("href");
        var $approved = 1;
        // Check all input validation
        $($id + " input").each(function(){
            if (!$(this).val()) {
                $(this).css('border-color', 'red');
                $(this).parent().parent().find("i.alert").removeClass("alert-hide");
                $approved = 0;
            } else {
                $(this).parent().parent().find("i.alert").addClass("alert-hide");
            }
        });
        if ($approved !== 1) return false;
        // Add class visited to style css
        if (tab.attr("class")=="visited"){
            tab.removeClass("visited");
        } else {
            tab.addClass("visited");
        }
    },
    'tabClass': 'bwizard-steps-o','nextSelector': '.button-next', 'previousSelector': '.button-previous'
});

</script>

<script type="text/javascript">
//精美radio部分
(function($) {
	//radio部分
            $.icheck = {
                init: function() {
                    var _this = this;
                    _this._checkbox = "checkbox";
                    _this._radio = "radio";
                    _this._disabled = "disabled";
                    _this._enable = "enable";
                    _this._checked = "checked";
                    _this._hover = "hover";
                    _this._arrtype = [_this._checkbox, _this._radio];
                    _this._mobile = /ipad|iphone|ipod|android|blackberry|windows phone|opera mini|silk/i.test(navigator.userAgent);
                    $.each(_this._arrtype, function(k, v) {
                        _this.click(v);
                        if(!_this._mobile){
                            _this.mouseover(v);
                            _this.mouseout(v);
                        }
                    });
                },
                click: function(elem) {
                    var _this = this;
                    elem = "." + elem;
                    $(document).on("click", elem, function() {
                        var $this = $(this),
                            _ins = $this.find("ins");
                        if (!(_ins.hasClass(_this._disabled) || _ins.hasClass(_this._enable))) {
                            if ( !! _ins.hasClass(_this._checked)) {
                                _ins.removeClass(_this._checked).addClass(_this._hover);
                            } else {
                                if (/radio/ig.test(elem)) {
                                    var _name = $this.attr("name");
                                    $(elem + "[name=" + _name + "]").find("ins").removeClass(_this._checked);
                                }
                                $(elem).find("ins").removeClass(_this._hover);
                                _ins.addClass(_this._checked);
                            }
                        }
                    });
                },
                mouseover: function(elem) {
                    var _this = this;
                    elem = "." + elem;
                    $(document).on("mouseover", elem, function() {
                        var $this = $(this);
                        var _ins = $this.find("ins");
                        if (!(_ins.hasClass(_this._disabled) || _ins.hasClass(_this._enable) || _ins.hasClass(_this._checked))) {
                            _ins.addClass(_this._hover);
                            $this.css("cursor","pointer");
                        } else{
                            $this.css("cursor","default");
                        }
                    });
                },
                mouseout: function(elem) {
                    var _this = this;
                    elem = "." + elem;
                    $(document).on("mouseout", elem, function() {
                        $(elem).find("ins").removeClass(_this._hover);
                    });
                }
            };

            $.icheck.init();

        })(jQuery);
</script>
   
<script>
//文件上传

function upload(){
	//默认上传按钮不可用
	$("#btnUpload").attr("disabled", true);

	//上传按钮点击事件
	$("#btnUpload").click(function() {
		//上传按钮修改为可用
		$(this).attr("disabled", true);
		uploadFunction();
	});
	
	// 文件修改时
	$("#uploadFile").change(function() {
		$("#progressbar").width(0);
		$("#progressbar").height(0);
		$("#progressbar").text("");
		$("#btnUpload").show();
		$("#btnUpload").val("上传");
		var file = $(this).prop("files");
		if (file.length != 0) {
			$("#btnUpload").attr("disabled", false);
		}
	});
}

//文件上传
function uploadFunction() {
	var uploadFile = $("#uploadFile").get(0).files[0]; //获取文件对象
	// FormData 对象
	var form = new FormData();
	form.append("file", uploadFile); // 文件对象
	$.ajax({
		cache : false,
		type : "POST",
		url : "./DataHandlingImportUpload.do",
		contentType : false,
		//contentType设置为false。因为是由<form>表单构造的FormData对象，且已经声明了属性enctype="multipart/form-data"
		//如果不是用<form>表单构造FormData对象,append()的第二个参数应是文件对象，即$('#file')[0].files[0],contentType也要设置为‘false’。
		processData : false,//processData设置为false。因为data值是FormData对象，不需要对数据做处理
		data : form,
		xhr : function() { //获取ajaxSettings中的xhr对象，为它的upload属性绑定progress事件的处理函数
			myXhr = $.ajaxSettings.xhr();
			if (progressFunction && myXhr.upload) { //检查进度函数和upload属性是否存在
				//绑定progress事件的回调函数
				myXhr.upload.addEventListener("progress",
						progressFunction, false);
			}
			return myXhr; //xhr对象返回给jQuery使用
		},
		error : function(request) {
			layer.msg("请求失败！", {icon: 2});
		},
		success : function(data) {
			//$("#btnUpload").val("上传完成");
			var jsonO = eval(data);
			if(jsonO[0].info =="error"){
				layer.msg("上传失败!");
				$("#btnUpload").attr("disabled", true);
				$("#progressbar").width(0);
				$("#progressbar").height(0);
				$("#progressbar").text("");
			}else{
				$("#filePath").val(jsonO[0].info);
				$("#progressbar").text("100% / 完成");
				var sourceType=$("#dataSourceType").val();
				if(sourceType=="excel"){
					getSheetName();
				}
			}
		}
	});
}

//进度条控制
function progressFunction(evt) {
	if (evt.lengthComputable) {//lengthComputable，表示进度信息是否可用的布尔值；target，对应的 XHR 对象；
		var completePercent = Math.round(evt.loaded / evt.total * 100);//loaded:已经接收的字节数；,total:响应数据的预期总字节数，根据 Content-Length 响应头部确定
		$("#progressbar").text(completePercent+"%");
		$("#progressbar").width((completePercent*10));
		$("#progressbar").height(34);
		//$("#btnUpload").val("进度");
		$("#btnUpload").hide();
	}
}
</script>
<style>
        .checkbox,.radio{*zoom:1;height: 24px; line-height: 24px; margin: 10px;}
        .checkbox ins,.radio ins{display: inline-block;*display: inline;*zoom:1; width: 23px; height: 22px; vertical-align: middle; background: url(static/images/blue.png) no-repeat; margin-right: 8px; -webkit-transition:all 0.1s linear; -moz-transition:all 0.1s linear; -o-transition:all 0.1s linear; -ms-transition:all 0.1s linear; transition:all 0.1s linear;vertical-align: middle;}
        .checkbox ins{background-position: 0px 0px; }
        .radio ins{background-position: -120px 0px; }
        .checkbox .hover{background-position: -24px 0px; }
        .checkbox .checked{background-position: -48px 0px; }
        .checkbox .enable{background-position: -96px 0px;}
        .checkbox .disabled{background-position: -72px 0px;}
        .radio .hover{background-position: -144px 0px;}
        .radio .checked{background-position: -168px 0px;}
        .radio .enable{background-position: -214px 0px;}
        .radio .disabled{background-position: -191px 0px;}
        .checkbox span,.radio span{display: inline-block;*display: inline;*zoom:1;vertical-align: middle; }
        .zsk,.sjy{margin: 5px auto;height: 200px;overflow: auto;background-color: #eee}
</style>
